#include "fibcom.h"

const char *init_cmds[]={
    "AT+CAVIMS=1\r\n",
    "AT+CSCA?\r\n",
    "AT+CSCA=\"+8613800755500\"\r\n",
    "AT+CPMS=\"SM\"\r\n",
    "AT+CNMI=2,1,0,0,0\r\n",
    "AT+CMGF=1\r\n"
};

void send_text(char * num, char *msg){
    char content[256];
    for (int i=0; i<6; ++i){
        rt_device_write(device_ext_uart, 0, init_cmds[i], strlen(init_cmds[i]));
    }

    sprintf(content, "AT+CMGS=\"%s\"\r\n", num);
    rt_device_write(device_ext_uart, 0, content, strlen(content));

    sprintf(content, "%s\x1A", msg);
    rt_device_write(device_ext_uart, 0, content, strlen(content));
}

void text_send(int argc, char **argv){
    if (argc >= 3){
        send_text(argv[1], argv[2]);
        rt_kprintf("%s\n", argv[2]);
    }
}

MSH_CMD_EXPORT(text_send, send text message)
